from rest_framework.generics import ListCreateAPIView
from users.models import User
from meiduo_admin.serializers.users import UserSerializer
from meiduo_admin.utils import PageNum


class UserView(ListCreateAPIView):
    """获取用户数据"""
    # def get(self, request):

    # 指定查询集
    # queryset = User.objects.all()
    # 序列化器
    serializer_class =UserSerializer
    # 分页器
    pagination_class = PageNum

    def get_queryset(self):
        if self.request.query_params.get('keyword') == '':
            return User.objects.all()
        else:
            queryset = User.objects.filter(username__contains=self.request.query_params.get('keyword'))
            return queryset


